package com.cms.jy.copy;

import com.alibaba.fastjson.JSONObject;
import com.cms.jy.GenMusicByApi;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class TestJy {
    public static void main(String[] args) throws Exception {
        GenMusicByApi genMusicByApi = new GenMusicByApi();
        // 创建草稿
        String draftId = genMusicByApi.createDraftAndGetId();
        System.out.println(draftId);
        // 开头 云烟效果视频
        String start1VideoUrl = genMusicByApi.RES_TPL_URL + "/FW-6EBW--MLV0-389L-BWRL-KVFBKHRQJBBZ.mp4";
        double startTime1 = genMusicByApi.parseFrameTime("00:00:00:06");
        double vstartDuration1 = genMusicByApi.parseFrameTime("00:00:01:18") -startTime1 ;
        draftId = genMusicByApi.addVideo(start1VideoUrl, 0.0, 0.0,
                1920, 1080, draftId, genMusicByApi.calculateCoverY(665), genMusicByApi.calculateCoverX(-219),
                1.59, 1.59, 3.6/vstartDuration1, startTime1, "test_55", null, vstartDuration1, "模糊",
                0.7, 0.0, null,
                null, null, null, null, null, false, null,
                null, null, 1.0, "screen",null, 90.0);

        String finalDraftId = draftId;
        String result = genMusicByApi.saveDraft(finalDraftId, "测试22", null,0);
        log.info("草稿保存成功，URL: {}", result);

        int progress = 0;
        do {
            JSONObject status = null;
            try {
                status = genMusicByApi.queryDraftStatus(draftId);
                progress =  status.getIntValue("progress");
                log.info("进度：{}%，{}/{}", status.getString("progress"), status.getIntValue("completed_files"), status.getIntValue("total_files"));
            } catch (Exception e) {
                log.error("查询进度失败:{}", e.getMessage());
            }
        } while (progress!=100);
    }
}
